package com.ctd.springframework.core.io;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;

/**
 * Resource
 *
 * @author chentudong
 * @time 2019/3/24 13:04
 */
public interface Resource extends InputStreamSource {
    /**
     * exists
     *
     * @return boolean
     */
    boolean exists();

    /**
     * isReadable
     *
     * @return boolean
     */
    default boolean isReadable() {
        return exists();
    }

    /**
     * isOpen
     *
     * @return boolean
     */
    default boolean isOpen() {
        return false;
    }

    /**
     * isFile
     *
     * @return boolean
     */
    default boolean isFile() {
        return false;
    }

    /**
     * getURL
     *
     * @return URL
     * @throws IOException IOException
     */
    URL getURL() throws IOException;

    /**
     * getURI
     *
     * @return URI
     * @throws IOException IOException
     */
    URI getURI() throws IOException;

    /**
     * getFile
     *
     * @return File
     * @throws IOException IOException
     */
    File getFile() throws IOException;

    /**
     * Return a description for this resource,
     * to be used for error output when working with the resource.
     * <p>Implementations are also encouraged to return this value
     * from their {@code toString} method.
     *
     * @see Object#toString()
     */
    String getDescription();
}
